/******************************************/
/* DTD Inquisitor 2                       */
/* Copyright: University of Pennsylvania  */
/* Author: Byron Choi                     */
/* Date: 9/2001                           */
/* Contact: kkchoi@gradient.cis.upenn.edu */
/******************************************/
package automata;

import java.util.HashSet;
import java.util.Iterator;

/* Alphabet is a set of Labels */
public class Alphabet extends HashSet<Label> implements Cloneable {

	private static final long serialVersionUID = 1L;

	public static Alphabet empty() {
		return new Alphabet();
	}

	public boolean add(Label l) {
		return super.add(l);
	}

	public boolean exist(Label l) {
		Iterator<Label> i = iterator();
		while (i.hasNext()) {
			if (((Label) (i.next())).equals(l)) {
				return true;
			}
		}
		return false;
	}
	
	public static Alphabet union(Alphabet al1, Alphabet al2) {
		Alphabet al3 = Alphabet.empty();
		Iterator<Label> i1 = al1.iterator();
		while (i1.hasNext()) {
			al3.add(i1.next());
		}

		Iterator<Label> i2 = al2.iterator();
		while (i2.hasNext()) {
			al3.add(i2.next());
		}
		return al3;
	}

	public String toString() {
		String str = new String();
		Iterator<Label> i = this.iterator();
		while (i.hasNext()) {
			Label l = (Label) (i.next());
			str += l.toString() + " ";
		}
		return str;
	}

}
